//
//  View+First.swift
//  BasicTools
//
//  Created by S JZ on 2025/5/28.
//

import SwiftUI

struct FirstAppear: ViewModifier {
    var firstAppear: () -> Void
    
    @State private var isFirst: Bool = true
    
    init(firstAppear: @escaping () -> Void) {
        self.firstAppear = firstAppear
    }
    
    func body(content: Content) -> some View {
        content
            .onAppear {
                if isFirst {
                    isFirst = false
                    firstAppear()
                }
            }
    }
}

extension BasicWrapper where Base: View {
    public func onFirstAppear(_ firstAppear: @escaping () -> Void) -> some View{
        self.base.modifier(FirstAppear(firstAppear: firstAppear))
    }
}



